
<?php
$email= trim($_REQUEST['email']);
$pass= trim($_REQUEST['password']);
require 'dbcon.php';
$sql="select * from users where email='{$email}'";
$result=$db->query($sql);
$num=$result->num_rows;
setcookie("email",$email);
if($num==1)
{
    $row=$result->fetch_array();
    if($row['password']==$pass)
    {
        session_start();
        $_SESSION['userinfo']= array(
            'id'=>$row['id'],
            'email'=>$row['email'],
             'nickname'=>$row['nickname'],
             'avatar'=>$row['avatar'] ,
             'slug'=>$row['slug'] ,
            'bio'=>$row['bio'] 
        );
        header("Location:index.php");
    }
    else
    {
        header("Location:login.php?error=2");
    }
 
}
 else
{
   header("Location:login.php?error=1");    
}
